package com.songcha.library_common.helper

import android.content.Context
import com.songcha.library_common.LibraryCommon

class SharedPreferenceHelper {
    companion object{
        fun setInt(name:String,key:String,value:Int):Boolean{
            val sp=LibraryCommon.getContext().getSharedPreferences(name, Context.MODE_PRIVATE)
            val editor = sp.edit()
            editor.putInt(key,value)
            return editor.commit()
        }

        fun getInt(name:String,key:String,def:Int = -1):Int{
            val sp=LibraryCommon.getContext().getSharedPreferences(name, Context.MODE_PRIVATE)
            return sp.getInt(key,def)
        }

        fun setLong(name:String,key:String,value:Long):Boolean{
            val sp=LibraryCommon.getContext().getSharedPreferences(name, Context.MODE_PRIVATE)
            val editor = sp.edit()
            editor.putLong(key,value)
            return editor.commit()
        }

        fun getLong(name:String,key:String,def:Long = -1L):Long{
            val sp=LibraryCommon.getContext().getSharedPreferences(name, Context.MODE_PRIVATE)
            return sp.getLong(key,def)
        }

        fun setBoolean(name:String,key:String,value:Boolean):Boolean{
            val sp=LibraryCommon.getContext().getSharedPreferences(name, Context.MODE_PRIVATE)
            val editor = sp.edit()
            editor.putBoolean(key,value)
            return editor.commit()
        }

        fun getBoolean(name:String,key:String,defValue:Boolean = false):Boolean{
            val sp=LibraryCommon.getContext().getSharedPreferences(name, Context.MODE_PRIVATE)
            return sp.getBoolean(key,defValue)
        }

        fun setString(name:String,key:String,value:String):Boolean{
            val sp=LibraryCommon.getContext().getSharedPreferences(name, Context.MODE_PRIVATE)
            val editor = sp.edit()
            editor.putString(key,value)
            return editor.commit()
        }

        fun getString(name:String,key:String):String{
            val sp=LibraryCommon.getContext().getSharedPreferences(name, Context.MODE_PRIVATE)
            return sp.getString(key,"")?:""
        }
    }
}